% twoD_plot.m  2/12/2014  Parker MacCready
%
% plots the results of twoD_extractor.m

clear; close all;
addpath('../alpha'); Tdir = toolstart;
outdir = [Tdir.output,'twoD_out/'];

% choose which file to plot
[fn,pth] = uigetfile([outdir,'*.nc'],'Select file to plot...');
infile = [pth,fn];

% find whichCase and daterang by parsing name
ii = find(fn=='_');
if length(ii)~=2; disp('Cannot parse name'); break; end;
whichCase = fn(1:ii(1)-1);
td0 = fn(ii(1)+1:ii(2)-1);
td1 = fn(ii(2)+1:end-3);
ds0 = datestr(str2num(td0));
ds1 = datestr(str2num(td1));

switch whichCase
    case 'meanSurfaceVel'
        lon = nc_varget(infile,'lon');
        lat = nc_varget(infile,'lat');
        u = nc_varget(infile,'mean_u');
        v = nc_varget(infile,'mean_v');
        spd = sqrt(u.^2 + v.^2);
        mask = nc_varget(infile,'mask');
        H = nc_varget(infile,'H');
        
        clims = .5*[0 1];
        aa = [-123.25 -122 47 48.5];
        clat = cos(pi*mean(aa(3:4))/180);
        delta = .01;
        llat = aa(3):delta:aa(4);
        llon = aa(1):delta/clat:aa(2);
        [LON,LAT] = meshgrid(llon,llat);
        U = interp2(lon,lat,u,LON,LAT);
        V = interp2(lon,lat,v,LON,LAT);

        spd(~mask) = NaN;
        %
        figure; Z_fig;
        %
        Z_pcolorcen(lon,lat,spd);
        colormap(cool)
        cm = colormap;
        cm = brighten(cm,.8);
        colormap(cm);
        caxis(clims);
        axis(aa)
        colorbar('eastoutside')
        Z_dar;
        xlabel('Longitude'); ylabel('Latitude')
        title(['Mean surface vel. (m s^{-1}) ',ds0,' : ',ds1,' ']);
        Z_addcoast('combined',Tdir.coast);
        hold on
        if 0
            contour(lon,lat,H,[200 200],'r');
            [xt,yt] = Z_lab('lr');
            text(xt,yt,'200 m','color','r', ...
                'horizontalalignment','r','fontweight','bold')
        end
        
        Z_velvec_generic(LON,LAT,U,V,'ll',.5)
        
        if 1
            set(gcf,'position',[10 10 800 1200]);
            set(gcf,'PaperPositionMode','auto');
            print('-djpeg100',[outdir,strrep(fn,'.nc',''),'.jpg']);
        end
        
end

